//
//  QGHelpPageTableViewCell.m
//  QuanGou
//
//  Created by qqqq on 15/11/20.
//  Copyright © 2015年 DongYongFei. All rights reserved.
//

#import "QGHelpPageTableViewCell.h"
#import <UIImageView+WebCache.h>

@interface QGHelpPageTableViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *picture;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property (weak, nonatomic) IBOutlet UILabel *distanceLabel;
@property (weak, nonatomic) IBOutlet UILabel *stateLabel;

@end
@implementation QGHelpPageTableViewCell

- (void)awakeFromNib {
    // Initialization code
    
}

- (void)setHelpPageModel:(QGHelpPageModel *)helpPageModel {
    if (_helpPageModel != helpPageModel) {
        _helpPageModel = nil;
        _helpPageModel = helpPageModel;
        
        [self layoutModels];
    }
}

- (void)layoutModels {
//    self.helpPageModel.userico是nsstring类型的url
    [self.picture sd_setImageWithURL:[NSURL URLWithString:self.helpPageModel.userico] placeholderImage:nil];
    self.titleLabel.text = self.helpPageModel.title;
    
    NSString *timeString;
    if ([self.helpPageModel.time doubleValue] / 86400 > 1)
    {
        timeString = [NSString stringWithFormat:@"%ld", (NSInteger)[self.helpPageModel.time doubleValue] / 86400];
        timeString = [NSString stringWithFormat:@"%@天前", timeString];
    }else if ([self.helpPageModel.time doubleValue] / 3600 > 1 && [self.helpPageModel.time doubleValue] / 86400 < 1)
    {
        timeString = [NSString stringWithFormat:@"%ld", (NSInteger)[self.helpPageModel.time doubleValue] / 3600];
        timeString = [NSString stringWithFormat:@"%@小时前", timeString];
    }else if ([self.helpPageModel.time doubleValue] / 3600 < 1)
    {
        timeString = [NSString stringWithFormat:@"%ld", (NSInteger)[self.helpPageModel.time doubleValue] / 60];
        timeString = [NSString stringWithFormat:@"%@分钟前", timeString];
    }else {
        timeString = self.helpPageModel.creatTime;
    }
    
    

    
    self.addressLabel.text = [NSString stringWithFormat:@"%@  %@", self.helpPageModel.address, timeString];
    self.distanceLabel.text = self.helpPageModel.distance;
    self.stateLabel.text = self.helpPageModel.state;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
